import requests
from ck_data_preparation import CK_Data_Preparation
from ck_connect import ClickHouseConnector
from data_count_method import DataCount
from response_data import ReSponseData
class Execute:
    def dailyPower(self,sql1,sql2):
        capacity = CK_Data_Preparation().data_select(sql1)
        dailyPower = CK_Data_Preparation().data_select(sql2)
        dailyFullHour = dailyPower/capacity
        url_value =  ReSponseData().all_request('get',"https://xuntian-test2.tclpv.com/api/pomp-data-analysis/powerKanban/info",None,{
                "id": "GF220921163313000561",
                "t": "1726210597176"
            },'dailyFullHour')
        DataCount().count(dailyFullHour,url_value)

if __name__ == "__main__":
    sql1 = "SELECT param_value FROM his_0306.device_param_all WHERE tenant_id = 'P8950' AND device_id = 'HP00500032260530' AND param_name = 'INV.capacity' limit 1"
    sql2 = "SELECT param_value FROM his_0306.device_param_all WHERE receive_time = (SELECT IF(MAX(receive_time) = toDateTime('1970-01-01 00:00:00', 'Asia/Shanghai'), toStartOfDay(toTimeZone(now(), 'Asia/Shanghai')), MAX(receive_time)) ASmax_receive_time FROM his_0306.device_param_all WHERE receive_time >= toStartOfDay(toTimeZone(now(), 'Asia/Shanghai')) AND tenant_id = 'P8950' AND device_id = 'HP00500032260530')"
    demo = Execute()
    demo.dailyPower(sql1,sql2)
    # sql = "SELECT param_value FROM his_0306.device_param_all WHERE tenant_id = 'P8950' AND device_id = 'HP00500032260530' AND param_name = 'INV.capacity' limit 1"
    # sql = ["INSERT INTO his_0306.power_record_all(tenant_id, business_type, code, calcu_property, start_time, end_time, param_name, param_value, `type`, create_time, old_param_value) VALUES('P3168', 1, '370882', 1,toDateTime('2024-08-24 00:00:00', 'Asia/Shanghai'), toDateTime('2024-08-25 00:00:00', 'Asia/Shanghai'), 'elec', '10', 1, toDateTime('2024-08-24 00:00:00', 'Asia/Shanghai'), '')",
    #        "INSERT INTO his_0306.power_record_all(tenant_id, business_type, code, calcu_property, start_time, end_time, param_name, param_value, `type`, create_time, old_param_value) VALUES('P3168', 1, '370882', 1,toDateTime('2024-08-25 00:00:00', 'Asia/Shanghai'), toDateTime('2024-08-26 00:00:00', 'Asia/Shanghai'), 'elec', '10', 1, toDateTime('2024-08-24 00:00:00', 'Asia/Shanghai'), '')"]
    # # capacity = CK_Data(connector).ck_capacity('param_value','P8950','HP00500032260530','INV.capacity')
    # dailyPower = CK_Data(connector).ck_dailypower('param_value','P8950','HP00500032260530',1)
    # dailyFullHour = dailyPower/capacity
    # print(dailyPower,capacity,dailyFullHour)
    # url_value =  ReSponseData().all_request('get',"https://xuntian-test2.tclpv.com/api/pomp-data-analysis/powerKanban/info",None,{
    #         "id": "GF220921163313000561",
    #         "t": "1726210597176"
    #     },'capacity')

    # DataCount().count(sql_value,url_value)
    # print(sql_value)